---
- name: ensure packages required for taskotron-trigger are installed (yum)
  package: name={{ item }} state=present enablerepo={{ extra_enablerepos }}
  with_items:
    - fedmsg
    - fedmsg-hub
    - taskotron-trigger
    # needed for cron script
    - python-resultsdb_api
  when: ansible_distribution_major_version|int < 22

- name: ensure packages required for taskotron-trigger are installed (dnf)
  dnf: name={{ item }} state=present enablerepo={{ extra_enablerepos }}
  with_items:
    - fedmsg
    - fedmsg-hub
    - taskotron-trigger
    # needed for cron script
    - python-resultsdb_api
  when: ansible_distribution_major_version|int > 21 and ansible_cmdline.ostree is not defined

- name: generate trigger configuration
  template: src=trigger.cfg.j2 dest=/etc/taskotron/trigger.cfg owner=root group=root mode=0744
  notify:
  - restart fedmsg-hub

- name: generate trigger rules
  template: src={{ item }} dest=/etc/taskotron/trigger_rules.yml owner=root group=root mode=0744
  with_first_found:
    - trigger_rules.yml.j2.{{ deployment_type }}
    - trigger_rules.yml.j2
  notify:
  - restart fedmsg-hub

- name: copy fedmsg logging configuration
  copy: src=logging.py dest=/etc/fedmsg.d/logging.py owner=root group=root mode=0744
  notify:
  - restart fedmsg-hub

- name: install fetch_activity
  copy: src=fetch_activity.py dest=/root/fetch_activity.py owner=root group=root mode=0644

- name: create a dir for fetch_activity logs
  file: dest=/root/fetch_activity_logs mode=755 owner=root group=root state=directory

- name: copy fetch_activity cron job
  template: src=fetch_activity.cron.j2 dest=/etc/cron.d/fetch_activity.cron owner=root group=root mode=0644
  notify:
  - restart crond

- name: download critpath list
  get_url: url={{ trigger_critpath_url }} dest={{ trigger_critpath_file }} mode=0644 owner=fedmsg group=fedmsg

- name: create a cronjob to download crithpath list as a task-libabigail whitelist
  cron:
    name="download crithpath list"
    special_time=daily
    job="{ wget -O {{ trigger_critpath_file }} {{ trigger_critpath_url }}; chown fedmsg:fedmsg {{ trigger_critpath_file }}; } >& /dev/null"

- name: copy tmpfiles.d for trigger distgit cache
  template: src=tmpfiles.d.trigger.conf.j2 dest=/etc/tmpfiles.d/trigger.conf owner=root group=root mode=0644

- name: start and enable fedmsg-hub service
  service: name=fedmsg-hub enabled=yes state=started
